import { route, GET, POST } from 'awilix-express';

@route('/options')
export default class OptionsApi {

  constructor({ optionsService }) {
    this.optionsService = optionsService;
  }

  @route('/getOptionsAll')
  @GET()
  async getOptionsAll(req, res){
    const { success, data: list, message } = await this.optionsService.getOptionsAll();
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message, list);
  }

  @route('/getOptionslist')
  @POST()
  async getOptionslist(req, res) {
    const { t_no, mark } = req.body
    const { success, data: list, message } = await this.optionsService.getOptionslist({t_no, mark});
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message, list);
  }

  @route('/addOptions')
  @POST()
  async addOptions(req, res) {
    const { 
      t_name,
      t_no,
      t_customer,
      t_logos,
      t_tell,
      t_email,
      t_url,
      mark
     } = req.body;
    const { success, message } = await this.optionsService.addOptions({
      t_name,
      t_no,
      t_customer,
      t_logos,
      t_tell,
      t_email,
      t_url,
      mark
    });
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message);
  }

  @route('/delOptions')
  @POST()
  async delOptions(req, res) {
    const { t_no } = req.body;
    const { success, message } = await this.optionsService.delOptions({t_no});
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message);
  }


  @route('/updateOptions')
  @POST()
  async updateOptions(req, res) {
    const {
      t_name,
      t_no,
      t_customer,
      t_logos,
      t_tell,
      t_email,
      t_url,
    } = req.body;
    const { success, message } = await this.optionsService.updateOptions({
      t_name,
      t_no,
      t_customer,
      t_logos,
      t_tell,
      t_email,
      t_url,
    });
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message);
  }
}